home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 8052 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.2 KB  |  39 lines

  1. Path: news.InfoChan.COM!news
  2. From: alanj@infochan.com (Alan Johnston)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: A simple question for all the C++ gurus out there!
  5. Date: Tue, 13 Feb 1996 20:32:15 GMT
  6. Organization: InfoChannel Ltd
  7. Message-ID: <4fqshj$jje@daffodil.InfoChan.COM>
  8. References: <3120F95F.659@iglou.com>
  9. NNTP-Posting-Host: ntsa22.infochan.com
  10. X-Newsreader: Forte Free Agent 1.0.82
  11.  
  12. "Abe L. Getchell" <panther@iglou.com> wrote:
  13.  
  14. >I am trying to write a public member function that will use a private
  15. >data member from which it inherited from the base class.  This won't compile.
  16. >It gives me an error message like "A::a private data member not accessible in
  17. >class B".  Why won't this work if the prvate data member being inherited from
  18. >the base class A be a private data member of the derived class?
  19.  
  20. >Abe L. Getchell
  21.  
  22. >Please respond via E-Mail if possible...
  23.  
  24. Private members in base classes are not accessible in derived classes,
  25. unless you make the derived class a friend of the base class.
  26. Protected members are accessible in derived classes, which gives you
  27. pretty much the same result.  Like this:
  28.  
  29. class A {
  30. protected:
  31. int a;
  32. }
  33.  
  34. class B : public A {
  35. public:
  36. int GetA() { return a; };
  37. }
  38.  
  39.